package org.gdstash.character;

import org.gdstash.file.GDWriter;
import java.io.IOException;
import org.gdstash.file.GDReader;

public class GDcharUISkillSet
{
    private int skillSetID;
    private GDCharUISlot[] slots;
    
    public GDcharUISkillSet(final int numSlots) {
        this.skillSetID = 0;
        this.slots = new GDCharUISlot[numSlots];
    }
    
    public void read(final int version) throws IOException {
        if (version >= 7) {
            this.skillSetID = GDReader.readEncInt(true);
        }
        for (int i = 0; i < this.slots.length; ++i) {
            final GDCharUISlot slot = new GDCharUISlot();
            slot.read();
            this.slots[i] = slot;
        }
    }
    
    public void write(final int version) throws IOException {
        if (version >= 7) {
            GDWriter.writeInt(this.skillSetID);
        }
        for (int i = 0; i < this.slots.length; ++i) {
            this.slots[i].write();
        }
    }
    
    public int getByteSize(final int version) {
        int size = 0;
        if (version >= 7) {
            size += 4;
        }
        for (int i = 0; i < this.slots.length; ++i) {
            size += this.slots[i].getByteSize();
        }
        return size;
    }
}
